<!--工作经历表单-->
<template>
  <div class="form">
    <yd-cell-group>
      <yd-cell-item>
        <span slot="left" class="label required">语种</span>
        <xf-picker
          v-model="form.languageCode"
          ref="languageCode"
          placeholder="请选择语种"
          :valid="[{required: true, msg: '请选择语种'}]"
          :list="languages"
          slot="right"></xf-picker>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left" class="label required">语种熟练程度</span>
        <xf-picker
          v-model="form.languageSkilledCode"
          ref="languageSkilledCode"
          placeholder="请选择语种熟练程度"
          :valid="[{required: true, msg: '请选择语种熟练程度'}]"
          :list="langLevel"
          slot="right"></xf-picker>
      </yd-cell-item>
    </yd-cell-group>
    <div class="right-bottom">
      <mt-button type="default" size="small" @click="cancel">取消</mt-button>
      <mt-button type="primary" size="small" @click="onSubmit">保存</mt-button>
    </div>
  </div>
</template>
<script>
  import XfPicker from '../../../components/xf-picker/xf-picker.vue'
  import {dics, getDics} from '../../../common/js/dictionaries'
  import {mapGetters} from 'vuex'
  import {echo} from '../../../common/js/util'

  export default {
    components: {
      XfPicker},
    name: 'form-language',
    props: {
      detail: {type: null, default: () => { return {} }}
    },
    computed: {
      ...mapGetters([
        'userInfo'
      ])
    },
    data() {
      return {
        form: {
          personId: this.$route.query.id,
          id: '',
          languageCode: '',
          languageSkilledCode: ''
        },
        languages: [],
        langLevel: []
      }
    },
    methods: {
      getDics() {
        getDics(dics.languages, dics.langLevel).then(res => {
          this.languages = res[0]
          this.langLevel = res[1]
        })
      },
      cancel() {
        this.$emit('cancel')
      },
      onSubmit() {
        const form = Object.assign({}, this.form)
        this.$post('/admin/person/sapi/personal/records/perEntry/update/language', form, loading => {
          this.$message.loading(loading)
        }).then(res => {
          this.$emit('save')
        })
      }
    },
    created() {
      this.getDics()
      echo(this.form, this.detail)
    }
  }
</script>
